#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>

#define strlen myStrLen
typedef unsigned char uchar;
int myStrLen(char *s) {
	int n = 0;
	char* p = s;

	while (*p != 0) {
		p++;
		n++;
	}
	return n;
};

int StrStartWith(char* str, char* sub) {
	int sublen = myStrLen(sub);
	for (int i = 0; i < sublen; i++) {
		if (str[i] == 0 || str[i] != sub[i]) {
			return 0;
		}
	}
	return 1;
}

char* FindStr(char* src, char* m) {
	char *psrc = src;
	while (*psrc != 0) {
		if (StrStartWith(psrc, m)) {
			return psrc;
		}
		psrc++;
	}
	return 0;
};

void TraceChBetween(char* lbound, char* rbounf) {
	for (int i = 0; i < rbounf - lbound; i++) {
		putchar(lbound[i]);
	}
}
//#define _xdebug

void exec() {
	char patten[512] = { 0 };
	char patten_l[256] = { 0 };
	char patten_r[256] = { 0 };
	char src[512] = { 0 };
	char *src_rightmost;

	gets(patten);
	gets(src);

	char* pp = patten;
	char* ppf = patten_l;
	char* ppe = patten_r;

	while (*pp != 0 && *pp != '*') {
		*ppf = *pp;
		pp++;
		ppf++;
	}
	pp++;
	while (*pp != 0) {
		*ppe = *pp;
		pp++;
		ppe++;
	}



	int lpatten_len;
	int rpatten_len ;

	if (*patten_l == 0) {
		lpatten_len = 0;
	} else {
		lpatten_len = myStrLen(patten_l);
	}
	if (*patten_r == 0) {
		rpatten_len = 1;
	} else {
		rpatten_len = myStrLen(patten_r);
	}

	int srclen = myStrLen(src);
	src_rightmost = src + srclen;
	uchar l_match_map[512] = { -1 };
	uchar r_match_map[512] = { -1 };

	for (int i = 0; i < srclen; i++) {
		l_match_map[i] = StrStartWith(src + i, patten_l) == 0 ? 0 : 1;
		r_match_map[i] = StrStartWith(src + i, patten_r) == 0 ? 0 : 1;
	}
	#ifdef _xdebug
	for (int i = 0; i < srclen; i++) {
		putchar('0' + l_match_map[i]);
	}
	putchar('\n');
	for (int i = 0; i < srclen; i++) {
		putchar('0' + r_match_map[i]);
	}
	putchar('\n');
	#endif
	// Trace shortest match
	if (lpatten_len == 0) {
		puts(patten_r);
	} else if(*patten_r == 0) {
		puts(patten_l);
	} else{
		char* lb_shortest = src;
		char* rb_shortest = src_rightmost;

#if 0
		int min_t = 1 << 20;
		for (int l_pos = 0; l_pos < srclen; l_pos++) {
			if (l_match_map[l_pos] == 1) {

				for (int i = l_pos + lpatten_len; i < srclen; i++) {
					if (r_match_map[i] == 1) {
						if(i - l_pos < min_t){
							lb_shortest = src + l_pos;
							rb_shortest = src + i + rpatten_len;
							min_t = i - l_pos;
						}
						break;
					}
				}
			}
		}
#else
		int l_pos = 0;
		for (; l_pos < srclen; l_pos++) {
			if (l_match_map[l_pos] == 1) {
				lb_shortest = src + l_pos;
				break;
			}
		}
		for (int i = l_pos + lpatten_len; i < srclen; i++) {
			if (r_match_map[i] == 1) {
				rb_shortest = src + i + rpatten_len;
				break;
			}
		}
#endif
		TraceChBetween(lb_shortest, rb_shortest);
		putchar('\n');

	}
	// Trace longest match
	char* lb_longest = src;
	char* rb_longest = src_rightmost;
	int l_pos2 = 0;
	for (; l_pos2 < srclen; l_pos2++) {
		if (l_match_map[l_pos2] == 1) {
			lb_longest = src + l_pos2;
			break;
		}
	}
	for (int i = srclen - 1; i >= l_pos2 + lpatten_len; i--) {
		if (r_match_map[i] == 1) {
			rb_longest = src + i + rpatten_len;
			break;
		}
	}
	TraceChBetween(lb_longest, rb_longest);

#ifdef _xdebug
	putchar('\n');
#endif
}

int main() {
#ifdef _xdebug
	while (1) {
	exec();
	}
#else
	exec();
#endif
}